﻿@model SuperLottery.AdminPortal.Models.DrawModel

@{
	Layout = "~/Views/Shared/_DrawLayout.cshtml";
	ViewBag.Title = "新增公告";
}

@using (Html.BeginForm())
{
	@Html.ValidationSummary(true);
	<div>
		<table>
			<tr>
				<td>彩票种类</td>
				<td>
					@Html.DropDownListFor(m => m.IssuerGame, SuperLottery.AdminPortal.Models.StaticDatas.IssuerGameItems)
				</td>
			</tr>
			<tr>
				<td>开奖期号</td>
				<td>
					@Html.TextBoxFor(m => m.IssueNumber)
					@Html.ValidationMessageFor(m => m.IssueNumber)
					<input id="btnCrawl" type="button" value="抓取" onclick="crawl()" />
				</td>
			</tr>
			<tr>
				<td>开奖日期</td>
				<td>
					@Html.TextBoxFor(m => m.DrawDate, new { @Value = Model.DrawDate.ToString("yyyy-MM-dd") })
					@Html.ValidationMessageFor(m => m.DrawDate)
				</td>
			</tr>

			<tr>
				<td>开奖号码</td>
				<td>
					@Html.TextBoxFor(m => m.Numbers)
					@Html.ValidationMessageFor(m => m.Numbers)</td>
			</tr>
			<tr>
				<td>特殊号码</td>
				<td>
					@Html.TextBoxFor(m => m.BonusNumbers)
					@Html.ValidationMessageFor(m => m.BonusNumbers)</td>
			</tr>
			<tr>
				<td>销售金额</td>
				<td>
					@Html.TextBoxFor(m => m.SalesAmount)
					@Html.ValidationMessageFor(m => m.SalesAmount)</td>
			</tr>
			<tr>
				<td>奖池累计</td>
				<td>
					@Html.TextBoxFor(m => m.CumulativeAmount)
					@Html.ValidationMessageFor(m => m.CumulativeAmount)</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>中奖详情</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>
					<table>
						<thead>
							<tr>
								<th>奖项</th>
								<th>人数</th>
								<th>奖金</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td>@Html.EditorFor(model => model.Award1Name)</td>
								<td>
									@Html.EditorFor(model => model.Award1NumberOfWinners)</td>
								<td>
									@Html.EditorFor(model => model.Award1MoneyPerWinner)</td>
							</tr>
							<tr>
								<td>@Html.EditorFor(model => model.Award2Name)</td>
								<td>
									@Html.EditorFor(model => model.Award2NumberOfWinners)</td>
								<td>
									@Html.EditorFor(model => model.Award2MoneyPerWinner)</td>
							</tr>
							<tr>
								<td>@Html.EditorFor(model => model.Award3Name)</td>
								<td>
									@Html.EditorFor(model => model.Award3NumberOfWinners)</td>
								<td>
									@Html.EditorFor(model => model.Award3MoneyPerWinner)</td>
							</tr>
							<tr>
								<td>@Html.EditorFor(model => model.Award4Name)</td>
								<td>
									@Html.EditorFor(model => model.Award4NumberOfWinners)</td>
								<td>
									@Html.EditorFor(model => model.Award4MoneyPerWinner)</td>
							</tr>
							<tr>
								<td>@Html.EditorFor(model => model.Award5Name)</td>
								<td>
									@Html.EditorFor(model => model.Award5NumberOfWinners)</td>
								<td>
									@Html.EditorFor(model => model.Award5MoneyPerWinner)</td>
							</tr>
							<tr>
								<td>@Html.EditorFor(model => model.Award6Name)</td>
								<td>
									@Html.EditorFor(model => model.Award6NumberOfWinners)</td>
								<td>
									@Html.EditorFor(model => model.Award6MoneyPerWinner)</td>
							</tr>
							<tr>
								<td>@Html.EditorFor(model => model.Award7Name)</td>
								<td>
									@Html.EditorFor(model => model.Award7NumberOfWinners)</td>
								<td>
									@Html.EditorFor(model => model.Award7MoneyPerWinner)</td>
							</tr>
						</tbody>
					</table>

				</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>
					<input id="idSubmit" type="submit" value="提交" /></td>
			</tr>
		</table>
	</div>
}

<script type="text/javascript">
	function crawl() {
		$("#btnCrawl").val("正在抓取中...");
		$("#btnCrawl").attr({ disabled: "disabled" });
		var url = "/api/crawler/get/" + $("#IssueNumber").val();
		if ($("#IssuerGame").val() == "福彩-七乐彩") {
			url = "/api/crawler/getqilecai/" + $("#IssueNumber").val();
		}
		jQuery.ajax({
			url: url,
			success: function (data) {
				$("#IssueNumber").val(data.IssueNumber);
				$("#DrawDate").val(data.DrawDate);
				$("#Numbers").val(data.Numbers);
				$("#BonusNumbers").val(data.BonusNumbers);
				$("#SalesAmount").val(data.SalesAmount);
				$("#CumulativeAmount").val(data.CumulativeAmount);
				$("#Award1Name").val(data.Award1Name);
				$("#Award1NumberOfWinners").val(data.Award1NumberOfWinners);
				$("#Award1MoneyPerWinner").val(data.Award1MoneyPerWinner);
				$("#Award2Name").val(data.Award2Name);
				$("#Award2NumberOfWinners").val(data.Award2NumberOfWinners);
				$("#Award2MoneyPerWinner").val(data.Award2MoneyPerWinner);
				$("#Award3Name").val(data.Award3Name);
				$("#Award3NumberOfWinners").val(data.Award3NumberOfWinners);
				$("#Award3MoneyPerWinner").val(data.Award3MoneyPerWinner);
				$("#Award4Name").val(data.Award4Name);
				$("#Award4NumberOfWinners").val(data.Award4NumberOfWinners);
				$("#Award4MoneyPerWinner").val(data.Award4MoneyPerWinner);
				$("#Award5Name").val(data.Award5Name);
				$("#Award5NumberOfWinners").val(data.Award5NumberOfWinners);
				$("#Award5MoneyPerWinner").val(data.Award5MoneyPerWinner);
				$("#Award6Name").val(data.Award6Name);
				$("#Award6NumberOfWinners").val(data.Award6NumberOfWinners);
				$("#Award6MoneyPerWinner").val(data.Award6MoneyPerWinner);
				$("#Award7Name").val(data.Award7Name);
				$("#Award7NumberOfWinners").val(data.Award7NumberOfWinners);
				$("#Award7MoneyPerWinner").val(data.Award7MoneyPerWinner);
			},
			complete: function (xhr, msg) {
				if (xhr.statusText != "OK") {
					alert(xhr.statusText);
				}
				$("#btnCrawl").removeAttr("disabled");
				$("#btnCrawl").val("抓取");
			}
		});
	}
</script>
